home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / fragrouter / Libnet-0.99b / include / libnet / libnet-headers.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-26  |  11.7 KB  |  393 lines

  1. /*
  2.  *  $Id: libnet-headers.h,v 1.2 1999/05/27 02:32:19 dugsong Exp $
  3.  *
  4.  *  libnet-headers.h - Network routine library headers header file
  5.  *
  6.  *  Copyright (c) 1998, 1999 Mike D. Schiffman <mike@infonexus.com>
  7.  *                           route|daemon9 <route@infonexus.com>
  8.  *  All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in the
  17.  *    documentation and/or other materials provided with the distribution.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  20.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  23.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29.  * SUCH DAMAGE.
  30.  *
  31.  */
  32.  
  33. #ifndef __LIBNET_HEADERS_H
  34. #define __LIBNET_HEADERS_H
  35.  
  36. /* 
  37.  *  Standard (IPv4) header sizes in bytes.  OH WAIT.  THESE ARE NETWORK
  38.  *  STRUCTURES.  I'M SORRY.  OCTETS.
  39.  */
  40.  
  41. #define ARP_H           0x1c    /* ARP header:          28 bytes */
  42. #define DNS_H           0xc     /* DNS header base:     12 bytes */
  43. #define ETH_H           0xe     /* Etherner header:     14 bytes */
  44. #define IP_H            0x14    /* IP header:           20 bytes */
  45. #define ICMP_H          0x4     /* ICMP header base:     4 bytes */
  46. #define ICMP_ECHO_H     0x8     /* ICMP_ECHO header:     8 bytes */
  47. #define ICMP_MASK_H     0xc     /* ICMP_MASK header:    12 bytes */
  48. #define ICMP_UNREACH_H  0x8     /* ICMP_UNREACH header:  8 bytes */
  49. #define ICMP_TIMXCEED_H 0x8     /* ICMP_TIMXCEED header: 8 bytes */
  50. #define ICMP_TS_H       0x14    /* ICMP_TIMESTAMP headr:20 bytes */
  51. #define IGMP_H          0x8     /* IGMP header:          8 bytes */
  52. #define P_H             0xc     /* Psuedo header:       12 bytes */
  53. #define RIP_H           0x18    /* RIP header base:     24 bytes */
  54. #define TCP_H           0x14    /* TCP header:          20 bytes */
  55. #define UDP_H           0x8     /* UDP header:           8 bytes */
  56.  
  57.  
  58. /*
  59.  *  The pseudoheader for TCP/UDP checksums.
  60.  */
  61. struct libnet_pseudo_hdr
  62. {
  63.     u_long ip_src;      /* source IP address */
  64.     u_long ip_dst;      /* destination IP address */
  65.     u_char null;        /* padding octect */
  66.     u_char protocol;    /* TCP or UDP */
  67.     u_short len;        /* packet size */
  68. };
  69.  
  70.  
  71. /*
  72.  *  ICMP packet header prototype.  Too many O/S's define this differently.
  73.  *  Easy enough to solve that and define it here.
  74.  */
  75. struct libnet_icmp_hdr
  76. {
  77.     u_char icmp_type;
  78. /*
  79.  *  ICMP types.
  80.  */
  81. #ifndef     ICMP_ECHOREPLY
  82. #define     ICMP_ECHOREPLY                  0
  83. #endif
  84. #ifndef     ICMP_UNREACH
  85. #define     ICMP_UNREACH                    3
  86. #endif
  87. #ifndef     ICMP_SOURCEQUENCH
  88. #define     ICMP_SOURCEQUENCH               4
  89. #endif
  90. #ifndef     ICMP_REDIRECT
  91. #define     ICMP_REDIRECT                   5
  92. #endif
  93. #ifndef     ICMP_ECHO
  94. #define     ICMP_ECHO                       8
  95. #endif
  96. #ifndef     ICMP_ROUTERADVERT
  97. #define     ICMP_ROUTERADVERT               9
  98. #endif
  99. #ifndef     ICMP_ROUTERSOLICIT
  100. #define     ICMP_ROUTERSOLICIT              10
  101. #endif
  102. #ifndef     ICMP_TIMXCEED
  103. #define     ICMP_TIMXCEED                   11
  104. #endif
  105. #ifndef     ICMP_PARAMPROB
  106. #define     ICMP_PARAMPROB                  12
  107. #endif
  108. #ifndef     ICMP_TSTAMP
  109. #define     ICMP_TSTAMP                     13
  110. #endif
  111. #ifndef     ICMP_TSTAMPREPLY
  112. #define     ICMP_TSTAMPREPLY                14
  113. #endif
  114. #ifndef     ICMP_IREQ
  115. #define     ICMP_IREQ                       15
  116. #endif
  117. #ifndef     ICMP_IREQREPLY
  118. #define     ICMP_IREQREPLY                  16
  119. #endif
  120. #ifndef     ICMP_MASKREQ
  121. #define     ICMP_MASKREQ                    17
  122. #endif
  123. #ifndef     ICMP_MASKREPLY
  124. #define     ICMP_MASKREPLY                  18
  125. #endif
  126.     u_char icmp_code;
  127. /*
  128.  *  ICMP codes.
  129.  */
  130. #ifndef     ICMP_UNREACH_NET
  131. #define     ICMP_UNREACH_NET                0
  132. #endif
  133. #ifndef     ICMP_UNREACH_HOST
  134. #define     ICMP_UNREACH_HOST               1
  135. #endif
  136. #ifndef     ICMP_UNREACH_PROTOCOL
  137. #define     ICMP_UNREACH_PROTOCOL           2
  138. #endif
  139. #ifndef     ICMP_UNREACH_PORT
  140. #define     ICMP_UNREACH_PORT               3
  141. #endif
  142. #ifndef     ICMP_UNREACH_NEEDFRAG
  143. #define     ICMP_UNREACH_NEEDFRAG           4
  144. #endif
  145. #ifndef     ICMP_UNREACH_SRCFAIL
  146. #define     ICMP_UNREACH_SRCFAIL            5
  147. #endif
  148. #ifndef     ICMP_UNREACH_NET_UNKNOWN
  149. #define     ICMP_UNREACH_NET_UNKNOWN        6
  150. #endif
  151. #ifndef     ICMP_UNREACH_HOST_UNKNOWN
  152. #define     ICMP_UNREACH_HOST_UNKNOWN       7
  153. #endif
  154. #ifndef     ICMP_UNREACH_ISOLATED
  155. #define     ICMP_UNREACH_ISOLATED           8
  156. #endif
  157. #ifndef     ICMP_UNREACH_NET_PROHIB
  158. #define     ICMP_UNREACH_NET_PROHIB         9
  159. #endif
  160. #ifndef     ICMP_UNREACH_HOST_PROHIB
  161. #define     ICMP_UNREACH_HOST_PROHIB        10
  162. #endif
  163. #ifndef     ICMP_UNREACH_TOSNET
  164. #define     ICMP_UNREACH_TOSNET             11
  165. #endif
  166. #ifndef     ICMP_UNREACH_TOSHOST
  167. #define     ICMP_UNREACH_TOSHOST            12
  168. #endif
  169. #ifndef     ICMP_UNREACH_FILTER_PROHIB
  170. #define     ICMP_UNREACH_FILTER_PROHIB      13
  171. #endif
  172. #ifndef     ICMP_UNREACH_HOST_PRECEDENCE
  173. #define     ICMP_UNREACH_HOST_PRECEDENCE    14
  174. #endif
  175. #ifndef     ICMP_UNREACH_PRECEDENCE_CUTOFF
  176. #define     ICMP_UNREACH_PRECEDENCE_CUTOFF  15
  177. #endif
  178. #ifndef     ICMP_REDIRECT_NET
  179. #define     ICMP_REDIRECT_NET               0
  180. #endif
  181. #ifndef     ICMP_REDIRECT_HOST
  182. #define     ICMP_REDIRECT_HOST              1
  183. #endif
  184. #ifndef     ICMP_REDIRECT_TOSNET
  185. #define     ICMP_REDIRECT_TOSNET            2
  186. #endif
  187. #ifndef     ICMP_REDIRECT_TOSHOST
  188. #define     ICMP_REDIRECT_TOSHOST           3
  189. #endif
  190. #ifndef     ICMP_TIMXCEED_INTRANS
  191. #define     ICMP_TIMXCEED_INTRANS           0
  192. #endif
  193. #ifndef     ICMP_TIMXCEED_REASS
  194. #define     ICMP_TIMXCEED_REASS             1
  195. #endif
  196. #ifndef     ICMP_PARAMPROB_OPTABSENT
  197. #define     ICMP_PARAMPROB_OPTABSENT        1
  198. #endif
  199.  
  200.     u_short icmp_sum;
  201.  
  202.     union
  203.     {
  204.         struct
  205.         {
  206.             u_short id;
  207.             u_short seq;
  208.         }echo;
  209.  
  210. #undef icmp_id
  211. #undef icmp_seq
  212. #define icmp_id     hun.echo.id
  213. #define icmp_seq    hun.echo.seq
  214.  
  215.         u_long gateway;
  216.         struct
  217.         {
  218.             u_short pad;
  219.             u_short mtu;
  220.         }frag;
  221.     }hun;
  222.     union
  223.     {
  224.         struct
  225.         {
  226.             n_time its_otime;
  227.             n_time its_rtime;
  228.             n_time its_ttime;
  229.         }ts;
  230.         struct
  231.         {
  232.             struct ip idi_ip;
  233.             /* options and then 64 bits of data */
  234.         }ip;
  235.         u_long mask;
  236.         char data[1];
  237.  
  238. #undef icmp_mask
  239. #define icmp_mask    dun.mask
  240. #undef icmp_data
  241. #define icmp_data    dun.data
  242.  
  243. #undef icmp_otime
  244. #define icmp_otime   dun.ts.its_otime
  245. #undef icmp_rtime
  246. #define icmp_rtime   dun.ts.its_rtime
  247. #undef icmp_ttime
  248. #define icmp_ttime   dun.ts.its_ttime
  249.     }dun;
  250. };
  251.  
  252.  
  253. /*
  254.  *  IGMP header.
  255.  */
  256. struct libnet_igmp_hdr
  257. {
  258.     u_char igmp_type;
  259.     u_char igmp_code;
  260.     u_short igmp_sum;
  261.     struct in_addr igmp_group;
  262. };
  263.  
  264.  
  265. /* 
  266.  *  Ethernet packet header prototype.  Too many O/S's define this differently.
  267.  *  Easy enough to solve that and define it here.
  268.  */
  269. struct libnet_ethernet_hdr
  270. {
  271. #ifndef ETHER_ADDR_LEN
  272. #define ETHER_ADDR_LEN 6
  273. #endif
  274.     u_char  ether_dhost[ETHER_ADDR_LEN];    /* destination ethernet address */
  275.     u_char  ether_shost[ETHER_ADDR_LEN];    /* source ethernet address */
  276.     u_short ether_type;                     /* packet type ID */
  277. };
  278.  
  279. #define ETHERTYPE_PUP           0x0200  /* PUP protocol */
  280. #define ETHERTYPE_IP            0x0800  /* IP protocol */
  281. #define ETHERTYPE_ARP           0x0806  /* Addr. resolution protocol */
  282. #define ETHERTYPE_REVARP        0x8035  /* reverse Addr. resolution protocol */
  283. #define ETHERTYPE_VLAN          0x8100  /* IEEE 802.1Q VLAN tagging */
  284. #define ETHERTYPE_LOOPBACK      0x9000  /* used to test interfaces */
  285.  
  286. #if (!__GLIBC__)
  287. struct ether_addr
  288. {
  289.     u_char  ether_addr_octet[6];
  290. };
  291. #endif
  292.  
  293. /* 
  294.  *  ARP packet header prototype.  Too many O/S's define this differently.
  295.  *  Easy enough to solve that and define it here.
  296.  */
  297. struct libnet_arp_hdr
  298. {
  299.     u_short ar_hrd;                         /* format of hardware address */
  300. #define ARPHRD_ETHER    1                   /* ethernet hardware format */
  301.     u_short ar_pro;                         /* format of protocol address */
  302.     u_char  ar_hln;                         /* length of hardware address */
  303.     u_char  ar_pln;                         /* length of protocol addres */
  304.     u_short ar_op;                          /* operation type */
  305. #define ARPOP_REQUEST    1                  /* req to resolve address */
  306. #define ARPOP_REPLY      2                  /* resp to previous request */
  307. #define ARPOP_REVREQUEST 3                  /* req protocol address given hardware */
  308. #define ARPOP_REVREPLY   4                  /* resp giving protocol address */
  309. #define ARPOP_INVREQUEST 8                  /* req to identify peer */
  310. #define ARPOP_INVREPLY   9                  /* resp identifying peer */
  311.  
  312.     /*
  313.      *  These should implementation defined but I've hardcoded eth/IP.
  314.      */
  315.     u_char ar_sha[6];                         /* sender hardware address */
  316.     u_char ar_spa[4];                         /* sender protocol address */
  317.     u_char ar_tha[6];                         /* target hardware address */
  318.     u_char ar_tpa[4];                         /* target protocol address */
  319. };
  320.  
  321.  
  322. /*
  323.  *  Base DNS header.
  324.  */
  325. struct libnet_dns_hdr
  326. {
  327.     u_short id;             /* DNS packet ID */
  328.     u_short flags;          /* DNS flags */
  329.     u_short num_q;          /* Number of questions */
  330.     u_short num_answ_rr;    /* Number of answer resource records */
  331.     u_short num_auth_rr;    /* Number of authority resource records */
  332.     u_short num_addi_rr;    /* Number of additional resource records */
  333. };
  334.  
  335.  
  336. /*
  337.  *  Base RIP (routing information protocol) header.
  338.  */
  339. struct libnet_rip_hdr
  340. {
  341.     u_char cmd;             /* RIP command */
  342. #define RIPCMD_REQUEST      1   /* want info */
  343. #define RIPCMD_RESPONSE     2   /* responding to request */
  344. #define RIPCMD_TRACEON      3   /* turn tracing on */
  345. #define RIPCMD_TRACEOFF     4   /* turn it off */
  346. #define RIPCMD_POLL         5   /* like request, but anyone answers */
  347. #define RIPCMD_POLLENTRY    6   /* like poll, but for entire entry */
  348. #define RIPCMD_MAX          7
  349.     u_char ver;             /* RIP version */
  350. #define RIPVER_0            0
  351. #define RIPVER_1            1
  352. #define RIPVER_2            2
  353.     u_short rd;             /* Zero (v1) or Routing Domain (v2) */
  354.     u_short af;             /* Address family */
  355.     u_short rt;             /* Zero (v1) or Route Tag (v2) */
  356.     u_long addr;            /* IP address */
  357.     u_long mask;            /* Zero (v1) or Subnet Mask (v2) */
  358.     u_long next_hop;        /* Zero (v1) or Next hop IP address (v2) */
  359.     u_long metric;          /* Metric */
  360. };
  361.  
  362.  
  363. #if 0
  364. struct libnet_snmp_hdr
  365. {
  366.     /* ASN.1 BER support first */
  367. };
  368. #endif
  369.  
  370. /*
  371.  *  TCP options structure.
  372.  */
  373. struct tcpoption
  374. {
  375.     u_char tcpopt_list[MAX_IPOPTLEN];
  376. };
  377.  
  378.  
  379. #if (__linux__)
  380. /*
  381.  *  Linux has a radically different IP options structure from BSD.
  382.  */
  383. struct ipoption
  384. {
  385.     struct  in_addr ipopt_dst;          /* first-hop dst if source routed */
  386.     char ipopt_list[MAX_IPOPTLEN];      /* options proper */
  387. };
  388. #endif
  389.  
  390. #endif  /* __LIBNET_HEADERS_H */
  391.  
  392. /* EOF */
  393.